package com.sgb.kjwl.view.ui.activity.manage;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.databinding.DataBindingUtil;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivitySpecialQualificationDetailBinding;
import com.sgb.kjwl.model.entity.manage.SpecialQualificationEntity;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 资质详情页
 */
public class SpecialQualificationDetailActivity extends AppActivity {
    ActivitySpecialQualificationDetailBinding binding;

    @Override
    protected void initView() {
        super.initView();
        binding = DataBindingUtil.setContentView(this, R.layout.activity_special_qualification_detail);
        binding.setLifecycleOwner(this);
        SpecialQualificationEntity bean = (SpecialQualificationEntity) getIntent().getSerializableExtra("detail");
        binding.setBean(bean);
        if (!TextUtils.isEmpty(bean.getCertificateTime())) {
            Date time = new Date(Long.parseLong(bean.getCertificateTime()));
            SimpleDateFormat dateformat = new SimpleDateFormat("yyyy年MM月dd日");
            String dateStr = dateformat.format(time);
            binding.tv6.setText(dateStr);
        }
        if (bean.getCustomFieldList().size() > 0) {
            LayoutInflater inflater = LayoutInflater.from(this);
            for (int i = 0; i < bean.getCustomFieldList().size(); i++) {
                SpecialQualificationEntity.NewAddEntity entity = bean.getCustomFieldList().get(i);
                if (!TextUtils.isEmpty(entity.getFieldKey()) && !TextUtils.isEmpty(entity.getFieldValue())) {
                    View view = inflater.inflate(R.layout.item_new_add, null);
                    TextView tv_title = view.findViewById(R.id.tv_title);
                    TextView tv_content = view.findViewById(R.id.tv_content);
                    tv_title.setText(entity.getFieldKey());
                    tv_content.setText(entity.getFieldValue());
                    binding.llAdd.addView(view);
                }
            }
        }

        binding.btnEnterEnterprise.setOnClickListener(v -> {
            ShopInfoForCompanyTradesActivity.startAct(SpecialQualificationDetailActivity.this,
                    bean.getCompanyId(), bean.getCompanyNo(), 5, 1);
        });
    }
}
